<template>
  <div class="layout-route">
      <div class="card card-search">
          <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
              <el-form-item label="队列执行名称" prop="group_name">
                  <el-input v-model.trim="queryParams.group_name" placeholder="请输入队列执行名称" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="队列执行方法" prop="queue_function">
                  <el-input v-model.trim="queryParams.queue_function" placeholder="请输入队列执行方法" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
              </el-form-item>
               <el-form-item label=" ">
                  <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
          </el-form>
      </div>

      <div class="card">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" @click="showDetailDialog({}, 'add')">添加</el-button>
                </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
          <el-table v-loading="loading" :data="tableData" border script>
            <el-table-column label="ID" prop="id" width="80"></el-table-column>
              <el-table-column label="队列分组名称" prop="group_name" min-width="200"></el-table-column>
              <el-table-column label="状态" prop="status" min-width="60">
                  <template slot-scope="scope">
                      {{ scope.row.status | formatLabelByValueFuzzy(STATUS_LIST) }}
                  </template>
              </el-table-column>
              <el-table-column label="mq配置标识" prop="mq_config" min-width="100"></el-table-column>
              <el-table-column label="队列名称" prop="queue_name" min-width="100"></el-table-column>
              <el-table-column label="队列交换机名" prop="exchange_name" min-width="200"></el-table-column>
              <el-table-column label="队列绑定key" prop="bind_key" min-width="200"></el-table-column>
              <el-table-column label="队列执行方法" prop="queue_function" min-width="200"></el-table-column>
              <el-table-column label="最大进程数" prop="max_process_num" min-width="100"></el-table-column>
              <el-table-column label="处理数据能力" prop="max_do_ready_num" min-width="100"></el-table-column>
              <el-table-column label="操作" min-width="160" fixed="right">
                  <template slot-scope="scope">
                      <el-button type="text"  icon="el-icon-edit" @click="showDetailDialog(scope.row, 'edit')">编辑</el-button>
                      <el-button type="text"  icon="el-icon-edit" @click="showAuditDialog(scope.row)">审核</el-button>
                  </template>
              </el-table-column>
          </el-table>
          <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>
      </div>
      <detail-dialog v-model="detailDialog.visible" v-if="detailDialog.visible" :params="detailDialog.data" :type="detailDialog.type" @success="handleQuery"></detail-dialog>
      <audit-dialog v-model="auditDialog.visible" v-if="auditDialog.visible" :params="auditDialog.data" @success="handleQuery"></audit-dialog>
  </div>
</template>

<script>
import { queryList } from '@/api/system/mq'
import { STATUS_LIST } from './constant'
import DetailDialog from './components/DetailDialog.vue'
import AuditDialog from './components/AuditDialog.vue'
export default {
  name: 'SystemMQList',
  components: { DetailDialog, AuditDialog },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 表格数据
          tableData: [],
          STATUS_LIST,
          pageInfo: {
              page: 1,
              limit: 10,
          },
          // 查询参数
          queryParams: {
              group_name: undefined,
              queue_function: undefined,
          },
          detailDialog: {
              visible: false,
              data: {},
              type: ''
          },
          auditDialog: {
              visible: false,
              data: {},
          },
      }
  },
  created() {
      this.getList()
  },
  methods: {
      showDetailDialog(row, type) {
          this.detailDialog.visible=true
          this.detailDialog.data=row
          this.detailDialog.type=type
      },
      showAuditDialog(row) {
        this.auditDialog.visible=true
        this.auditDialog.data=row
      },
      //列表
      getList() {
          this.loading = true
          const qyparams = {
              ...this.pageInfo,
              ...this.queryParams,
          }
          queryList(qyparams)
              .then(response => {
                  this.tableData = response.data.list
                  this.total = response.data.total
              })
              .finally(() => {
                  this.loading = false
              })
      },

      // 搜索按钮操作
      handleQuery() {
          this.pageInfo.page = 1
          this.getList()
      },

      // 重置按钮操作
      resetQuery() {
          this.resetForm('queryForm')

          this.handleQuery()
      },
  },
}
</script>
